<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例4</title>
    <link rel="stylesheet" href="../css/index.css">
    <style>
        .tc {
            border: 1px solid orange;
            width: 300px;
            height: 200px;
            margin: 0 auto;
            background-color: palegoldenrod;
            display: none;
            position: absolute;
            z-index: 1;
        }
        
        .cz {
            flex-direction: row-reverse;
            padding: 2px 0;
            border: 1px orange solid;
            background-color: peru;
        }
    </style>
</head>

<body>
    <div style="position: relative; width: 300px; margin: 50px auto;">
        <div class="content" style="width: 100px;">
            <button onclick="tanchu()">弹出层</button>
        </div>
        <div class="tc">
            <div class="flex cz">
                <button onclick="gb()">X</button>
            </div>
        </div>
    </div>

    <div id="zz" style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;background-color: #000;opacity: 0.4;display: none;">

    </div>
    <script>
        let mystyle = document.querySelector('body').style
        let tc = document.querySelector('.tc')
        let zz = document.querySelector('#zz')

        function tanchu() {
            zz.style.display = 'block'
            tc.style.display = 'block'
        }

        function gb() {
            zz.style.display = 'none'
            tc.style.display = 'none'
        }
    </script>
</body>

</html>